import akka.stm.Ref;

/**
 * Represents a vending machine
 * 
 * @author SNelson
 * 
 */
public class VendingMachine
{
	/**
	 * A reference to the state of the vending machine
	 */
	private Ref<VendingMachineState> state = null;

	/**
	 * The initial stocked state of the vending machine
	 */
	public static final VendingMachineState INITIAL_STATE = new VendingMachineState(
		6, 6);

	/**
	 * Constructor
	 */
	public VendingMachine()
	{
		state = new Ref<VendingMachineState>(INITIAL_STATE);
	}

	/**
	 * Executes the given transaction on this vending machine
	 * 
	 * @param transaction
	 *            The transaction to execute
	 * @return The results of the transaction
	 */
	public Boolean executeTransaction(VendingMachineTransaction transaction)
	{
		return transaction.execute();
	}

	/**
	 * Gets a reference to the current state of the vending machine
	 * 
	 * @return The reference to the current state of the vending machine
	 */
	public Ref<VendingMachineState> getState()
	{
		return state;
	}
}
